﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package reprise.ui {
    import flash.events.*;
    import reprise.commands.*;
    import reprise.events.*;
    import reprise.data.*;
    import reprise.controls.html.*;
    import reprise.data.validators.*;

    public class AbstractInput extends UIComponent implements IInput {

        protected var m_validator:IValidator;
        public var m_id:int;
        protected var m_fieldname:String;
        public var m_priority:int = 0
        protected var m_required:Boolean;
        protected var m_data;
        protected var m_queueParent:CompositeCommand;
        protected var m_autovalidates:Boolean = true

        public function validator_complete(_arg1:CommandEvent):void{
            dispatchEvent(new CommandEvent(Event.COMPLETE, _arg1.success));
        }
        public function setName(_arg1:String):void{
            setFieldName(_arg1);
        }
        public function setValidator(_arg1:IValidator):void{
            m_validator = _arg1;
        }
        public function executesAsynchronously():Boolean{
            return ((m_validator) ? (m_validator is IAsynchronousCommand) : false);
        }
        override public function setFocus(_arg1:Boolean, _arg2:String):void{
            super.setFocus(_arg1, _arg2);
            if (((_arg1) && (m_canBecomeKeyView))){
                this.addEventListener(KeyboardEvent.KEY_DOWN, self_keyDown);
            } else {
                this.removeEventListener(KeyboardEvent.KEY_DOWN, self_keyDown);
            };
        }
        public function markAsInvalid():void{
            addCSSPseudoClass("error");
        }
        public function get id():int{
            return (m_id);
        }
        public function setRequired(_arg1:Boolean):void{
            m_required = _arg1;
        }
        public function get priority():int{
            return (m_priority);
        }
        public function fieldName():String{
            return (m_fieldname);
        }
        public function required():Boolean{
            return (m_required);
        }
        public function data(){
            return (m_data);
        }
        public function setData(_arg1):void{
            m_data = _arg1;
        }
        public function setValue(_arg1):void{
            throw (new Error("AbstractInput.setValue needs to be overwritten!"));
        }
        protected function self_keyDown(_arg1:KeyboardEvent):void{
            if (handleKeyEvent(_arg1)){
                _arg1.preventDefault();
                _arg1.stopImmediatePropagation();
                _arg1.stopPropagation();
            };
        }
        public function set id(_arg1:int):void{
            m_id = _arg1;
        }
        public function performValidation():void{
            if (!m_validator){
                return;
            };
            if ((m_validator is IAsynchronousCommand)){
                m_validator.addEventListener(Event.COMPLETE, validator_complete);
            };
            m_validator.setValue(value());
            m_validator.execute();
        }
        public function didSucceed():Boolean{
            var _local1:Boolean;
            if (!m_validator){
                if (m_required){
                    _local1 = ((!((value() == null))) && (!((value() == ""))));
                } else {
                    _local1 = true;
                };
            } else {
                _local1 = m_validator.didSucceed();
            };
            if (_local1){
                markAsValid();
            } else {
                markAsInvalid();
            };
            return (_local1);
        }
        public function isCancelled():Boolean{
            if ((m_validator is IAsynchronousCommand)){
                return ((m_validator as IAsynchronousCommand).isCancelled());
            };
            return (false);
        }
        public function set priority(_arg1:int):void{
            m_priority = _arg1;
        }
        public function reset():void{
            if ((m_validator is IAsynchronousCommand)){
                (m_validator as IAsynchronousCommand).reset();
            };
        }
        public function validator():IValidator{
            return (m_validator);
        }
        protected function handleKeyEvent(_arg1:KeyboardEvent):Boolean{
            return (false);
        }
        public function markAsValid():void{
            removeCSSPseudoClass("error");
        }
        public function setQueueParent(_arg1:CompositeCommand):void{
            m_queueParent = _arg1;
        }
        public function setFieldName(_arg1:String):void{
            m_fieldname = _arg1;
        }
        public function isExecuting():Boolean{
            if ((m_validator is IAsynchronousCommand)){
                return ((m_validator as IAsynchronousCommand).isExecuting());
            };
            return (false);
        }
        public function value(){
            throw (new Error("AbstractInput.value needs to be overwritten!"));
        }
        public function execute(... _args):void{
            performValidation();
        }
        public function setFormat(_arg1:String):void{
            if (_arg1.charAt(0) == "/"){
                setValidator(new RegExpValidator(_arg1));
                return;
            };
            switch (_arg1){
                case "email":
                    setValidator(new EmailValidator());
                    break;
                case "decimal":
                    setValidator(new RegExpValidator("/[0-9]+"));
                    break;
                default:
                    throw (new Error(("Input format not supported: " + _arg1)));
            };
        }
        public function cancel():void{
            if ((m_validator is IAsynchronousCommand)){
                (m_validator as IAsynchronousCommand).cancel();
            };
        }
        public function setRequiredAttribute(_arg1:String):void{
            m_required = (((_arg1 == "required")) || ((_arg1 == "true")));
        }

    }
}//package reprise.ui 
